package com.xxxx.server.service.impl;

import com.xxxx.server.pojo.Department;
import com.xxxx.server.mapper.DepartmentMapper;
import com.xxxx.server.pojo.RespBean;
import com.xxxx.server.service.IDepartmentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author zhoubin
 * @since 2022-04-13
 */
@Service
public class DepartmentServiceImpl extends ServiceImpl<DepartmentMapper, Department> implements IDepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;
    @Override
    public List<Department> getalldep() {
        return departmentMapper.getalldep(-1);
    }

    @Override
    public Department adddep(Department department) {
        return departmentMapper.adddep(department);
    }

    @Override
    public RespBean deletedep(Integer did) {
        Department dep =new Department();
        dep.setId(did);
        departmentMapper.deletedep(dep);
        if (dep.getResult()==-2){
            return RespBean.error("有子部门");
        }
        if (dep.getResult()==-1){
            return RespBean.error("该部门有员工");
        }
        if (dep.getResult()==1){
            return RespBean.success("删除成功");
        }

        return RespBean.error("删除失败");

    }
}
